package com.mantou.proxyservice.proxeservice.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;





import com.mantou.proxyservice.proxeservice.entity.Proxy;
import com.mantou.proxyservice.proxeservice.service.ProxyService;
import com.mantou.proxyservice.utils.ReturnCode;
import com.mantou.proxyservice.utils.ReturnContainer;

@RequestMapping("/proxyservice")
public class ProxyRestApiController {

	private final Logger logger = LoggerFactory.getLogger(ProxyRestApiController.class);
	
	
	@Autowired
	private ProxyService proxyService;
	
	@RequestMapping(value = "/proxeservice/proxy/{id}", method = RequestMethod.GET)
	public ResponseEntity<ReturnContainer<Proxy>> getProxyById(@PathVariable Integer id){
		Proxy proxy = proxyService.findByPrimaryKey(id);
		ReturnContainer<Proxy> responseEnv = new ReturnContainer<Proxy>(ReturnCode.OK.getStatus(),proxy);
		return new ResponseEntity<ReturnContainer<Proxy>>(responseEnv, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/proxeservice/proxy", method = RequestMethod.POST)
	public ResponseEntity<ReturnContainer<Integer>> createProxy(@RequestBody Proxy proxy){
		Integer  result = proxyService.create(proxy);
		ReturnContainer<Integer> responseEnv = new ReturnContainer<Integer>(ReturnCode.OK.getStatus(),result);
		return new ResponseEntity<ReturnContainer<Integer>>(responseEnv, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/proxeservice/proxy/{id}", method = RequestMethod.DELETE)
	public ResponseEntity<ReturnContainer<Integer>> deleteProxyByPrimaryKey(@PathVariable Integer id){
		Integer  result = proxyService.deleteByPrimaryKey(id);
		ReturnContainer<Integer> responseEnv = new ReturnContainer<Integer>(ReturnCode.OK.getStatus(),result);
		return new ResponseEntity<ReturnContainer<Integer>>(responseEnv, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/proxeservice/proxy/{id}", method = RequestMethod.PUT)
	public ResponseEntity<ReturnContainer<Integer>> updateProxyByPrimaryKeySelective(@PathVariable Integer id, @RequestBody Proxy proxy){
		proxy.setId(id);
		Integer  result = proxyService.updateByPrimaryKeySelective(proxy);
		ReturnContainer<Integer> responseEnv = new ReturnContainer<Integer>(ReturnCode.OK.getStatus(),result);
		return new ResponseEntity<ReturnContainer<Integer>>(responseEnv, HttpStatus.OK);
	}
	
}
